package com.jrx.anytxn.accounting.job.voucherFile.step;

import com.jrx.anytxn.accounting.config.VoucherFileConfig;
import com.jrx.anytxn.accounting.constant.AccountBizConstant;
import com.jrx.anytxn.accounting.service.IVoucherInfoService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VoucherFileWriter implements ItemWriter<String> {

    @Autowired
    private IVoucherInfoService voucherInfoService;

    @Autowired
    private VoucherFileConfig voucherFileConfig;


    @Override
    public void write(List<? extends String> items) throws Exception {
        if(CollectionUtils.isNotEmpty(items)){
            voucherInfoService.generatingFile((List<String>) items,voucherFileConfig.getVoucherPath() ,
                    voucherFileConfig.getVoucherName(), AccountBizConstant.VOUCHER_FILE_TYPE);
        }
    }
}
